package main

import (
	"github.com/bingoohuang/gg/pkg/ss"
	"strings"
)

const netstatCmd = "netstat -anv -p tcp"

func parseLine(line string) NetstatLine {
	fields := strings.Fields(line)
	return NetstatLine{
		Proto:          fields[0],
		Recv:           ss.ParseInt(fields[1]),
		Send:           ss.ParseInt(fields[2]),
		LocalAddress:   fields[3],
		ForeignAddress: fields[4],
		State:          fields[5],
		PidProgram:     fields[8],
	}
}

// ➜  nettopology git:(master) ✗ netstat -anv -p tcp
// Active Internet connections (including servers)
// Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)     rhiwat shiwat    pid   epid  state    options
// tcp4       0      0  192.168.217.19.50382   101.37.150.39.1443     ESTABLISHED 131072 131768  70817      0 0x0102 0x00000020
// tcp4       0      0  127.0.0.1.9999         127.0.0.1.50381        ESTABLISHED 406975 146988  70817      0 0x0102 0x00000024
// tcp4       0      0  127.0.0.1.50381        127.0.0.1.9999         ESTABLISHED 401385 146988  70797      0 0x0102 0x00000008
// tcp4       0      0  192.168.217.19.50376   119.23.155.159.1443    ESTABLISHED 131072 131768  70817      0 0x0102 0x00000020
